﻿using System;
using Enyim.Caching.Configuration;
using RpcHelper;
using RpcModel;
using SqlExecHelper;
using SqlExecHelper.SetColumn;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.DAL
{
        internal class ServerVisitCensusDAL : SqlBasicClass
        {
                public ServerVisitCensusDAL () : base ("ServerVisitCensus")
                {

                }

                public void Clear (long serverId)
                {
                        base.Drop ("ServerId", serverId);
                }
                public ServerVisitCensus[] Query (IBasicPage paging, out long count)
                {
                        paging.InitOrderBy ("Id", false);
                        return base.Query<ServerVisitCensus> (paging.OrderBy, paging.Index, paging.Size, out count);
                }

                internal void SetShow (Guid id, string show)
                {
                        if(!base.Update (new ISqlSetColumn[] {
                                new SqlSetColumn("Show", System.Data.SqlDbType.BigInt){Value=show}
                        }, "Id", id))
                        {
                                throw new ErrorException ("rpc.visit.census.show.set.fail");
                        }
                }

                public void Reset (long serverId)
                {
                        base.Update (new ISqlSetColumn[] {
                                new SqlSetColumn("VisitNum", System.Data.SqlDbType.BigInt){Value=0},
                                new SqlSetColumn("SuccessNum", System.Data.SqlDbType.BigInt){Value=0},
                                new SqlSetColumn("FailNum", System.Data.SqlDbType.BigInt){Value=0},
                                new SqlSetColumn("TodayVisit", System.Data.SqlDbType.BigInt){Value=0},
                                new SqlSetColumn("TodayFail", System.Data.SqlDbType.BigInt){Value=0},
                                new SqlSetColumn("TodaySuccess", System.Data.SqlDbType.BigInt){Value=0},
                        }, "ServerId", serverId);
                }
        }
}
